package A1_回溯;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class LC_491非递减子序列 {
    LinkedList<Integer> path=new LinkedList<>();
    List<List<Integer>> result=new ArrayList<>();
    public List<List<Integer>> findSubsequences(int[] nums) {
        backtracking(nums,0);
        return result;
    }
    public void backtracking(int[] nums,int startIndex){
        if(path.size()>1)
            result.add(new ArrayList<>(path));
        HashSet<Integer> uset=new HashSet<>();
        for(int i=startIndex;i<nums.length;i++){
            if(!path.isEmpty() && nums[i]<path.getLast() || uset.contains(nums[i]))
                continue;
            path.add(nums[i]);
            uset.add(nums[i]);
            backtracking(nums,i+1);
            path.removeLast();
        }
        return;
    }
}
